# @Version        : 1.0
# @Update Time    : 2024/9/15 23:19
# @File           : data_scope.py
# @IDE            : PyCharm
# @Desc           : 获取数据权限
from typing import Optional, Union, TypeVar
from fastapi import Request
from src.core.base.orm.orm import AbstractORMModel

ORM = TypeVar("ORM", bound=AbstractORMModel)


class DataScope:
    def __init__(
        self,
        model: Union[str, ORM] = "",
        user_alias: Optional[str] = "user_id",
        dept_alias: Optional[str] = "dept_id",
    ):
        """
        获取当前用户数据权限对应的查询sql语句
        :param model
        :param user_alias: 用户id字段别名，默认为 'user_id'
        :param dept_alias: 部门id字段别名，默认为 'dept_id'
        """
        self.model = model
        self.user_alias = user_alias
        self.dept_alias = dept_alias

    def __call__(self, request: Request) -> str:
        """
        获取过滤sql语句
        0 仅本人数据权限
        1 本部门数据权限
        2 本部门及以下数据权限
        3 自定义数据权限
        4 全部数据权限
        :param request:
        :return:
        """
        pass
